package database

import "go_user_manager/internal/domain"

type User struct {
	ID       string `gorm:"type:uuid;default:uuid_generate_v4();primaryKey" json:"id"` // UUID
	UserName string `gorm:"type:varchar(255)" json:"user_name"`                        // Tenant name
	Password string `gorm:"type:varchar(255)" json:"password"`
	Email    string `gorm:"type:varchar(255)" json:"email"`
}

func (e *User) TableName() string {
	return "user"
}

func (u *User) BeforeUpdate() {
	// updateTime = time.Now
}

func (u *User) BeforeCreate() {
	// createTime = time.Now
	// updateTime = time.Now
}

func (u *User) ToDomain() *domain.User {
	return &domain.User{
		ID:       u.ID,
		UserName: u.UserName,
		Password: u.Password,
		Email:    u.Email,
	}
}

func (u *User) FromDomain(d *domain.User) {
	u.ID = d.ID
	u.UserName = d.UserName
	u.Password = d.Password
	u.Email = d.Email
}
